package com.atguigu.gulimallsearch.controller;

import com.atguigu.gulimallsearch.service.MallSearchService;
import com.atguigu.gulimallsearch.vo.SearchParam;
import com.atguigu.gulimallsearch.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Controller

public class SearchController {
    @Autowired
    MallSearchService mallSearchService;
//    @RequestMapping("/list.html")
    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request){
        searchParam.set_queryString(request.getQueryString());
        //1.根据传递的页面信息去es中查询商品
        SearchResult result= mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }
}
